21. Exercise: Use the Cursor

Use the Cursor and Finish the App

Alright, it's time to finish this app. You'll do this by displaying the data from the Cursor. The layout has a button, which triggers the onButtonClick method. It switches back and forth between the “Show Definition” and “Next Word” states.

Finish the nextWord and showDefinition methods so that when the definition is shown, it reveals the definition of the current word and when the “next word” button is clicked, it hides the definition and shows the next word. Throughout the code are TODO notes to help guide you.

The code I just showed for printing out all words and definitions is below, available for you to modify:

int wordCol = cursor.getColumnIndex(DroidTermsExampleContract.COLUMN_WORD);
int definitionCol = cursor.getColumnIndex(DroidTermsExampleContract.COLUMN_DEFINITION);
while (cursor.moveToNext()) {
String word = cursor.getString(wordCol);
String definition = cursor.getString(definitionCol);
Log.v(“Cursor Example”, word + “ - “ + definition);

Exercise Code

Exercise: T08.03-Exercise-FinishQuizExample

Check when done

SOLUTION:
  • I'm done!